﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Media;

namespace LightOMator.View
{
    public partial class ColorButton : UserControl
    {

        public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("Color",
                                                    typeof(Color),
                                                    typeof(ColorButton),
                                                    new PropertyMetadata(onColorChanged));

        private static void onColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ColorButton button = (ColorButton)d;
            Color color = (Color)e.NewValue;
            button.ButtonBackground.Color = color;
            button.ColorPicker.Color = color;
        }



        public Color Color
        {
            get { return (Color)GetValue(ColorProperty); }
            set { SetValue(ColorProperty, value); }
        }

        public ColorButton()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ColorPickerPopup.IsOpen = true;
        }

        private void ButtonOk_Click(object sender, RoutedEventArgs e)
        {
            ColorPickerPopup.IsOpen = false;
        }

        private void ColorPicker_ColorChanged(object sender, Color color)
        {
            Color = color;
        }
    }
}
